package com.pxxy.springboot.webcase.filter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/******************
 * @Author yejf
 * @Description TODO
 */
@Order(2)
@WebFilter({"/book/add.do","/book/search.do","/book/update.do"})
public class SpecialLetterFilter implements Filter {

    private static final Logger LOGGER = LoggerFactory.getLogger(SpecialLetterFilter.class);

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        LOGGER.debug("--特殊字符过滤器初始化完成...");
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        //直接通过
        LOGGER.debug("进入SpecialLetterFilter中的doFilter方法，这里包装了请求");
        //
        chain.doFilter(new SpecialLetterRequest((HttpServletRequest)request), response);
    }

    @Override
    public void destroy() {
        LOGGER.debug("SpecialLetterFilter销毁...");
    }
}
